﻿<!DOCTYPE html>
<html lang="zh_CN">

<head>
    <title>对象透明度</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="图形系统开发实战:进阶篇 示例">
    <meta name="author" content="hjq">
    <meta name="keywords" content="canvas,anygraph,javascript">
    <!-- frame所需脚本和样式 -->
    <link rel="stylesheet" href="../../script/bootstrap-3.3.5/css/bootstrap.min.css">   
    <link rel="stylesheet" href="../../script/codemirror/codemirror.css">
    <script src="../../script/lib/jquery-1.11.2.min.js"></script>
    <script src="../../script/codemirror/codemirror_merge.js"></script>
    <!-- 加载代码块 -->
	<link rel="stylesheet" href="../css/styles.css">
    <script src="../js/helper.js"></script>
    <script>
        var pageTitle = "对象透明度";
        var pageDesc = "调整Image对象透明度";
    </script>
</head>

<body style="margin:10px;">
    <div id="graphWrapper" data-type="graph" style="width:600px; height:550px; border:solid 1px #CCC;"></div>
    <label style="margin-top:20px; display:block;">透明度</label>
    <input type="range" id="slideBar" min="0" max="100" style="width:600px" value="60" />
</body>
<script type="module">
    import { Graph, Image, BgUtil } from "../../src/index.js";

    // graph对象
    let graph = new Graph({
        "target": "graphWrapper"
    });

    // 新建图层
    let layer = graph.addLayer();
    BgUtil.generateGrid(Object.assign({ "interval": 10, "graph": graph }, graph.getSize()));

    // 绘制图像
    let image = new Image({
        "x": 50,
        "y": 50,
        "width": 500,
        "height": 450,
        "style": { "opacity": 0.6 },
        "src": "../images/ma.png"
    });
    layer.getSource().add(image);
    graph.render();

    let slideBar = document.getElementById("slideBar");
    slideBar.addEventListener("change", function (e) {
        image.setStyle({ "opacity": this.value / 100 });
        graph.render();
    })

</script>

</html>